#include<iostream>
#include<stdio.h>
#include<wait.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
void Linux_error(const char * msg)
{
  fprintf(stderr,"%s: %s\n", msg, strerror(errno));
  exit(0);
}

pid_t Fork()
{
  pid_t retpid=0;
  if((retpid = fork()) < 0)
  {
    Linux_error("Fork error");
  }
  return retpid;
}

int main()
{
  int status;
  pid_t pid;
  printf("hello\n");//printf hello
  //两个执行流,从fork开始
  pid = Fork();

  printf("%d %d\n",pid ,!pid);//子进程执行流，pid是0;
  //子进程执行流，pid=0，父进程执行流拿到5674 !pid = 0;
  if(pid != 0)
  {
    if(waitpid(-1,&status,0) > 0)
    {
      if(WIFEXITED(status) != 0)
        printf("%d\n", WEXITSTATUS(status));//子进程正常退出码为2
    }
  }
  printf("Bye\n");

  exit(2);
  return 0;
}
